home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / Draw / Sources / BaseShp.cpp next >
Encoding:
Text File  |  1996-04-25  |  27.0 KB  |  966 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                BaseShp.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef BASESHP_H
  15. #include "BaseShp.h"
  16. #endif
  17.  
  18. #ifndef UTILS_H
  19. #include "Utils.h"
  20. #endif
  21.  
  22. #ifndef CONSTANT_H
  23. #include "Constant.h"
  24. #endif
  25.  
  26. #ifndef DEFINES_K
  27. #include "Defines.k"
  28. #endif
  29.  
  30. #ifndef DRAWCONT_H
  31. #include "DrawCont.h"
  32. #endif
  33.  
  34. #ifndef DRAWPART_H
  35. #include "DrawPart.h"
  36. #endif
  37.  
  38. #ifndef DRAWPART_H
  39. #include "DrawPart.h"
  40. #endif
  41.  
  42. #ifndef DRAWFRM_H
  43. #include "DrawFrm.h"
  44. #endif
  45.  
  46. #ifndef DRAWPRXY_H
  47. #include "DrawPrxy.h"
  48. #endif
  49.  
  50. #ifndef DRAWLINK_H
  51. #include "DrawLink.h"
  52. #endif
  53.  
  54. #ifndef DRAWCLIP_H
  55. #include "DrawClip.h"
  56. #endif
  57.  
  58. // ----- Part Layer -----
  59.  
  60. #ifndef FWAPLEVT_H
  61. #include "FWAplEvt.h"
  62. #endif
  63.  
  64. #ifndef FWFRMING_H
  65. #include "FWFrming.h"
  66. #endif
  67.  
  68. #ifndef FWUTIL_H
  69. #include "FWUtil.h"
  70. #endif
  71.  
  72. #ifndef FWSELECT_H
  73. #include "FWSelect.h"
  74. #endif
  75.  
  76. #ifndef FWITERS_H
  77. #include "FWIters.h"
  78. #endif
  79.  
  80. #ifndef FWINTER_H
  81. #include "FWInter.h"
  82. #endif
  83.  
  84. #ifndef FWPRMISE_H
  85. #include "FWPrmise.h"
  86. #endif
  87.  
  88. #ifndef FWDSCOPR_H
  89. #include "FWDscOpr.h"
  90. #endif
  91.  
  92. #ifndef FWSEMTRM_H
  93. #include "FWSemTrm.h"
  94. #endif
  95.  
  96. // ----- OS Layer -----
  97.  
  98. #ifndef FWACQUIR_H
  99. #include "FWAcquir.h"
  100. #endif
  101.  
  102. #ifndef FWEVENT_H
  103. #include "FWEvent.h"
  104. #endif
  105.  
  106. #ifndef FWRECSHP_H
  107. #include "FWRecShp.h"
  108. #endif
  109.  
  110. #ifndef FWTXTBOX_H
  111. #include "FWTxtBox.h"
  112. #endif
  113.  
  114. #ifndef FWLINSHP_H
  115. #include "FWLinShp.h"
  116. #endif
  117.  
  118. #ifndef FWOVLSHP_H
  119. #include "FWOvlShp.h"
  120. #endif
  121.  
  122. #ifndef FWRRCSHP_H
  123. #include "FWRRcShp.h"
  124. #endif
  125.  
  126. #ifndef FWODGEOM_H
  127. #include "FWODGeom.h"
  128. #endif
  129.  
  130. // ----- Foundation Includes -----
  131.  
  132. #ifndef FWSTREAM_H
  133. #include "FWStream.h"
  134. #endif
  135.  
  136. // ----- OpenDoc Includes -----
  137.  
  138. #ifndef SOM_ODTransform_xh
  139. #include <Trnsform.xh>
  140. #endif
  141.  
  142. //========================================================================================
  143. // Runtime Information
  144. //========================================================================================
  145.  
  146. #ifdef FW_BUILD_MAC
  147. #pragma segment odfdrawshapes
  148. #endif
  149.  
  150. //========================================================================================
  151. // RunTime Info
  152. //========================================================================================
  153.  
  154. FW_DEFINE_AUTO(CBaseShape)
  155. FW_DEFINE_CLASS_M1(CBaseShape, FW_MScriptable)
  156.  
  157. const FW_ClassTypeConstant LBaseShape = FW_TYPE_CONSTANT('s','h','b','a');
  158. FW_REGISTER_ARCHIVABLE_CLASS(LBaseShape, CBaseShape, CBaseShape::Read, 0, 0, CBaseShape::Write)
  159.  
  160. //========================================================================================
  161. // globals
  162. //========================================================================================
  163.  
  164. FW_CRectShape* CBaseShape::gWorkingHandle = NULL;
  165. unsigned long CBaseShape::gShapeCount = 0;
  166.  
  167. // [KVV] Constructing gDefaultStyle and gDefaultInk like this causes
  168. //    problems because of order of initialization
  169. // const FW_CStyle gDefaultStyle = FW_kNormalStyle;
  170. // const FW_CInk gDefaultInk = FW_kNormalInk;
  171.  
  172. const FW_EStandardStyles gDefaultStyle = FW_kNormalStyle;
  173. const FW_EStandardInks gDefaultInk = FW_kNormalInk;
  174.  
  175. //========================================================================================
  176. // class CShapeCollection
  177. //========================================================================================
  178.  
  179. FW_DEFINE_AUTO(CShapeCollection)
  180.  
  181. //========================================================================================
  182. // class CShapeCollectionIterator
  183. //========================================================================================
  184.  
  185. FW_DEFINE_AUTO(CShapeCollectionIterator)
  186.  
  187. //========================================================================================
  188. // class CBaseShape
  189. //========================================================================================
  190.  
  191. //----------------------------------------------------------------------------------------
  192. // CBaseShape::CBaseShape
  193. //----------------------------------------------------------------------------------------
  194.  
  195. CBaseShape::CBaseShape(short numberOfHandles, 
  196.                        unsigned short shapeType, 
  197.                        unsigned short renderVerb) :
  198.     FW_MScriptable(),
  199.     fSelected(FALSE),
  200.     fNumberOfHandles(numberOfHandles),
  201.     fShapeType(shapeType),
  202.     fPublishLink(NULL),
  203.     fSubscribeLink(NULL),
  204.     fRenderVerb(renderVerb),
  205.     fFrameInk(gDefaultInk),
  206.     fFillInk(gDefaultInk),
  207.     fFrameStyle(gDefaultStyle),
  208.     fFillStyle(gDefaultStyle),
  209.     fPromised(0),
  210.     fExternalizationIndex(0)
  211. {
  212.     InitStatic();
  213.     FW_END_CONSTRUCTOR
  214. }
  215.  
  216. //----------------------------------------------------------------------------------------
  217. // CBaseShape::CBaseShape
  218. //----------------------------------------------------------------------------------------
  219.  
  220. CBaseShape::CBaseShape(FW_CReadableStream& archive) :
  221.     FW_MScriptable(),
  222.     fPublishLink(NULL),
  223.     fSubscribeLink(NULL),
  224.     fSelected(FALSE),
  225.     fPromised(0),
  226.     fExternalizationIndex(0)
  227. {
  228.     InitStatic();
  229.     
  230.     archive >> fShapeType;
  231.     archive >> fNumberOfHandles;
  232.         
  233.     archive >> fFrameInk;
  234.     archive >> fFillInk;
  235.     archive >> fFrameStyle;
  236.     archive >> fFillStyle;
  237.  
  238.     archive >> fRenderVerb;
  239.     FW_END_CONSTRUCTOR
  240. }
  241.  
  242. //----------------------------------------------------------------------------------------
  243. // CBaseShape::InitStatic
  244. //----------------------------------------------------------------------------------------
  245.  
  246. void CBaseShape::InitStatic()
  247. {
  248.     if (gShapeCount == 0)
  249.     {
  250.         CBaseShape::gWorkingHandle = FW_NEW(FW_CRectShape, (FW_kZeroRect, FW_kFill));
  251.         CBaseShape::gWorkingHandle->SetInk(FW_kInvertInk);
  252.     }
  253.     
  254.     CBaseShape::gShapeCount++;
  255. }
  256.  
  257. //----------------------------------------------------------------------------------------
  258. // CBaseShape::~CBaseShape
  259. //----------------------------------------------------------------------------------------
  260.  
  261. CBaseShape::~CBaseShape()
  262. {
  263.     FW_START_DESTRUCTOR
  264.     FW_ASSERT(fPromised == 0);    // I should have resolved all my promises
  265.     
  266.     CBaseShape::gShapeCount--;
  267.     if (CBaseShape::gShapeCount == 0)
  268.         delete CBaseShape::gWorkingHandle;
  269. }
  270.  
  271. //----------------------------------------------------------------------------------------
  272. // CBaseShape::Removed
  273. //----------------------------------------------------------------------------------------
  274.  
  275. void CBaseShape::Removed(Environment* ev)
  276. {
  277. }
  278.  
  279. //----------------------------------------------------------------------------------------
  280. // CBaseShape::Deleted
  281. //----------------------------------------------------------------------------------------
  282.  
  283. void CBaseShape::Deleted(Environment* ev)
  284. {
  285. }
  286.  
  287. //----------------------------------------------------------------------------------------
  288. // CBaseShape::CheckPromise
  289. //----------------------------------------------------------------------------------------
  290.  
  291. void CBaseShape::CheckPromise(Environment* ev, FW_CPart* part)
  292. {
  293.     if (fPromised & FW_kLinkStorage)
  294.     {
  295.         //     I don't want to call FW_CDataInterchange::ResolveAllPromises for link promises
  296.         //    because I only want to resolve link promises involving this shape.
  297.         FW_ASSERT(fPublishLink != NULL && fPublishLink->IsPromised(ev));
  298.         fPublishLink->ResolveAllPromises(ev);
  299.     }
  300.     FW_ASSERT((fPromised & FW_kLinkStorage) == 0);    // because CBaseShape::Promised should have been called
  301.     
  302.     if (fPromised & FW_kClipboardStorage)
  303.         part->GetDataInterchange(ev)->ResolveClipboardPromise(ev);
  304.     FW_ASSERT((fPromised & FW_kClipboardStorage) == 0);        // because CBaseShape::Promised should have been called
  305.  
  306.     FW_ASSERT(fPromised == 0);
  307. }
  308.  
  309. //----------------------------------------------------------------------------------------
  310. // CBaseShape::Promised
  311. //----------------------------------------------------------------------------------------
  312.  
  313. void CBaseShape::Promised(FW_EStorageKinds storageKind, FW_Boolean state)
  314. {
  315.     if (state)
  316.         fPromised |= storageKind;
  317.     else
  318.         fPromised ^= fPromised & storageKind;
  319. }
  320.  
  321. //----------------------------------------------------------------------------------------
  322. // CBaseShape::TrackFeedback
  323. //----------------------------------------------------------------------------------------
  324.  
  325. void CBaseShape::TrackFeedback(Environment* ev,
  326.                                 ODFacet* facet,
  327.                                 FW_CGraphicContext& gc,
  328.                                 const FW_CPoint& anchorPoint, 
  329.                                 const FW_CPoint& currentPoint, 
  330.                                 FW_Boolean erase)
  331. {
  332.     if (!erase)
  333.         SetShapeGeometry(anchorPoint, currentPoint);
  334.  
  335.     RenderShape(ev, facet, gc);
  336. }
  337.  
  338. //----------------------------------------------------------------------------------------
  339. // CBaseShape::SelectShape
  340. //----------------------------------------------------------------------------------------
  341.  
  342. void CBaseShape::SelectShape(Environment* ev, FW_Boolean state)
  343. {
  344.     fSelected = state;
  345. }
  346.  
  347. //----------------------------------------------------------------------------------------
  348. // CBaseShape::ClearCache
  349. //----------------------------------------------------------------------------------------
  350.  
  351. void CBaseShape::ClearCache()
  352. {
  353. }
  354.  
  355. //----------------------------------------------------------------------------------------
  356. // CBaseShape::RenderHandles
  357. //----------------------------------------------------------------------------------------
  358. //    if asynchFacet is != NULL it means we are drawing asynchronously in a facet
  359.  
  360. void CBaseShape::RenderHandles(FW_CGraphicContext& gc)
  361. {    
  362.     FW_CPoint penSize = gc.DeviceToLogical(2, 2);
  363.     for (short i=1; i<=fNumberOfHandles; i++)
  364.     {
  365.         CalcHandle(i, CBaseShape::gWorkingHandle, penSize);    
  366.         CBaseShape::gWorkingHandle->Render(gc);
  367.     }
  368. }
  369.  
  370. //----------------------------------------------------------------------------------------
  371. // CBaseShape::CalcHandle
  372. //----------------------------------------------------------------------------------------
  373.  
  374. void CBaseShape::CalcHandle(short whichHandle, FW_CRectShape* handle, const FW_CPoint& penSize) const
  375. {
  376.     FW_CPoint pt;
  377.     GetHandleCenter(whichHandle, pt);
  378.     
  379.     FW_Fixed fx = penSize.x + FW_ODFixedToFixed(0x00008000);
  380.     FW_Fixed fy = penSize.y + FW_ODFixedToFixed(0x00008000);
  381. //    const FW_Fixed fx25 = FW_DoubleToFixed(2.5);
  382.     FW_CRect rect(pt.x - fx, pt.y - fy, pt.x + fx, pt.y + fy);
  383.     
  384.     handle->SetRectangle(rect);
  385. }
  386.  
  387. //----------------------------------------------------------------------------------------
  388. // CBaseShape::InSelectionRect
  389. //----------------------------------------------------------------------------------------
  390.  
  391. FW_Boolean CBaseShape::InSelectionRect(const FW_CRect& selectRect) const
  392. {
  393.     FW_CRect bounds = GetRectGeometry();
  394.     
  395.     FW_CRect temp(bounds);
  396.     temp.Intersection(selectRect);
  397.     
  398.     return bounds == temp;
  399. }
  400.  
  401. //----------------------------------------------------------------------------------------
  402. // CBaseShape::Flatten
  403. //----------------------------------------------------------------------------------------
  404.  
  405. void CBaseShape::Flatten(FW_CWritableStream& archive)
  406. {    
  407.     archive << fShapeType;
  408.     archive << fNumberOfHandles;
  409.     
  410.     archive << fFrameInk;
  411.     archive << fFillInk;
  412.     archive << fFrameStyle;
  413.     archive << fFillStyle;
  414.     
  415.     archive << fRenderVerb;
  416. }
  417.  
  418. //----------------------------------------------------------------------------------------
  419. // CBaseShape::MovedAfter
  420. //----------------------------------------------------------------------------------------
  421.  
  422. void CBaseShape::MovedAfter(Environment* ev, CBaseShape* shape)
  423. {
  424. FW_UNUSED(shape);
  425. }
  426.  
  427. //----------------------------------------------------------------------------------------
  428. // CBaseShape::MovedBefore
  429. //----------------------------------------------------------------------------------------
  430.  
  431. void CBaseShape::MovedBefore(Environment* ev, CBaseShape* shape)
  432. {
  433. FW_UNUSED(shape);
  434. }
  435.  
  436. //----------------------------------------------------------------------------------------
  437. // CBaseShape::MovedFirst
  438. //----------------------------------------------------------------------------------------
  439.  
  440. void CBaseShape::MovedFirst(Environment* ev)
  441. {
  442. }
  443.  
  444. //----------------------------------------------------------------------------------------
  445. // CBaseShape::MovedLast
  446. //----------------------------------------------------------------------------------------
  447.  
  448. void CBaseShape::MovedLast(Environment* ev)
  449. {
  450. }
  451.  
  452. //----------------------------------------------------------------------------------------
  453. // CBaseShape::RestoreShape
  454. //----------------------------------------------------------------------------------------
  455.  
  456. void CBaseShape::RestoreShape(Environment *ev, CDrawPart* drawPart)
  457. {
  458.     drawPart->AddShapeToPart(ev, this);
  459. }
  460.  
  461. //----------------------------------------------------------------------------------------
  462. // CBaseShape::SetFrozen
  463. //----------------------------------------------------------------------------------------
  464.  
  465. FW_Boolean CBaseShape::SetFrozen(FW_Boolean state)
  466. {
  467. FW_UNUSED(state);
  468.     return FALSE;    // Means I don't care
  469. }
  470.  
  471. //----------------------------------------------------------------------------------------
  472. // CBaseShape::IsFrozen
  473. //----------------------------------------------------------------------------------------
  474.  
  475. FW_Boolean CBaseShape::IsFrozen() const
  476. {
  477.     return FALSE;
  478. }
  479.  
  480. //----------------------------------------------------------------------------------------
  481. // CBaseShape::GetPenSize
  482. //----------------------------------------------------------------------------------------
  483.  
  484. FW_Fixed CBaseShape::GetPenSize() const
  485. {
  486.     return HasFrameStyle() ? fFrameStyle.GetPenSize() : FW_kFixed0;
  487. }
  488.  
  489. //----------------------------------------------------------------------------------------
  490. // CBaseShape::GetColor
  491. //----------------------------------------------------------------------------------------
  492. void CBaseShape::GetColor(FW_Boolean fill, FW_CColor& color)
  493. {
  494.     if (fill)
  495.         fFillInk.GetForeColor(color);
  496.     else
  497.         fFrameInk.GetForeColor(color);
  498. }
  499.  
  500. //----------------------------------------------------------------------------------------
  501. // CBaseShape::GetPattern
  502. //----------------------------------------------------------------------------------------
  503. FW_CPattern CBaseShape::GetPattern(FW_Boolean fill)
  504. {
  505.     if (fill)
  506.         return fFillStyle.GetPattern();
  507.     else
  508.         return fFrameStyle.GetPattern();
  509. }
  510.  
  511. //----------------------------------------------------------------------------------------
  512. // CBaseShape::UnshareInk
  513. //----------------------------------------------------------------------------------------
  514.  
  515. FW_CInk CBaseShape::UnshareInk(const FW_CInk& ink) const
  516. {
  517. //    Do not use the following syntax. It looks like the life time of temporaries
  518. //    is wrong causing a bad refcounting problem
  519. //    return (ink->GetRefCount() > 1) ? ink->Copy() : ink;
  520.  
  521.     if (ink.GetRefCount() > 1)
  522.         return ink.Copy();
  523.     else
  524.         return ink;
  525. }
  526.  
  527. //----------------------------------------------------------------------------------------
  528. // CBaseShape::UnshareStyle
  529. //----------------------------------------------------------------------------------------
  530.  
  531. FW_CStyle CBaseShape::UnshareStyle(const FW_CStyle& style) const
  532. {
  533. //    Do not use the following syntax. It looks like the life time of temporaries
  534. //    is wrong causing a bad refcounting problem
  535. //    return (style->GetRefCount() > 1) ? style->Copy() : style;
  536.  
  537.     if (style.GetRefCount() > 1)
  538.         return style.Copy();
  539.     else
  540.         return style;
  541. }
  542.  
  543. //----------------------------------------------------------------------------------------
  544. // CBaseShape::ChangeFrameColor
  545. //----------------------------------------------------------------------------------------
  546.  
  547. void CBaseShape::ChangeFrameColor(Environment* ev, CDrawPart* part, const FW_CColor& color)
  548. {
  549.     if (HasFrameStyle())
  550.     {
  551.         CheckPromise(ev, part);
  552.         
  553.         fFrameInk = UnshareInk(fFrameInk);
  554.         fFrameInk.SetForeColor(color);
  555.     }
  556. }
  557.  
  558. //----------------------------------------------------------------------------------------
  559. // CBaseShape::ChangeFramePattern
  560. //----------------------------------------------------------------------------------------
  561.  
  562. void CBaseShape::ChangeFramePattern(Environment* ev, CDrawPart* part, const FW_CPattern& pattern)
  563. {
  564.     if (HasFrameStyle())
  565.     {
  566.         CheckPromise(ev, part);
  567.         
  568.         fFrameStyle = UnshareStyle(fFrameStyle);
  569.         fFrameStyle.SetPattern(pattern);
  570.     }
  571. }
  572.  
  573. //----------------------------------------------------------------------------------------
  574. // CBaseShape::ChangeFillColor
  575. //----------------------------------------------------------------------------------------
  576.  
  577. void CBaseShape::ChangeFillColor(Environment* ev, CDrawPart* part, const FW_CColor& color)
  578. {
  579.     if (HasFillStyle())
  580.     {
  581.         CheckPromise(ev, part);
  582.         
  583.         fFillInk = UnshareInk(fFillInk);
  584.         fFillInk.SetForeColor(color);
  585.     }
  586. }
  587.  
  588. //----------------------------------------------------------------------------------------
  589. // CBaseShape::ChangeFillPattern
  590. //----------------------------------------------------------------------------------------
  591.  
  592. void CBaseShape::ChangeFillPattern(Environment* ev, CDrawPart* part, const FW_CPattern& pattern)
  593. {
  594.     if (HasFillStyle())
  595.     {
  596.         CheckPromise(ev, part);
  597.         
  598.         fFillStyle = UnshareStyle(fFillStyle);
  599.         fFillStyle.SetPattern(pattern);
  600.     }
  601. }
  602.  
  603. //----------------------------------------------------------------------------------------
  604. // CBaseShape::ChangePenSize
  605. //----------------------------------------------------------------------------------------
  606.  
  607. void CBaseShape::ChangePenSize(Environment* ev, CDrawPart* part, FW_Fixed newPenSize)
  608. {
  609.     if (HasFrameStyle())
  610.     {
  611.         CheckPromise(ev, part);
  612.         
  613.         ClearCache();
  614.         
  615.         fFrameStyle = UnshareStyle(fFrameStyle);
  616.         fFrameStyle.SetPenSize(newPenSize);
  617.     }
  618. }
  619.  
  620. //----------------------------------------------------------------------------------------
  621. // CBaseShape::SetSubscribeLink
  622. //----------------------------------------------------------------------------------------
  623.  
  624. void CBaseShape::SetSubscribeLink(Environment* ev, CDrawSubscribeLink *subscribeLink)
  625. {
  626. FW_UNUSED(ev);
  627.  
  628.     fSubscribeLink = subscribeLink;
  629. }
  630.  
  631. //----------------------------------------------------------------------------------------
  632. // CBaseShape::SetPublishLink
  633. //----------------------------------------------------------------------------------------
  634.  
  635. void CBaseShape::SetPublishLink(Environment* ev, CDrawPublishLink *publishLink)
  636. {
  637. FW_UNUSED(ev);
  638.  
  639.     fPublishLink = publishLink;
  640. }
  641.  
  642. //----------------------------------------------------------------------------------------
  643. // CBaseShape::AdjustRectForPenSize
  644. //----------------------------------------------------------------------------------------
  645.  
  646. void CBaseShape::AdjustRectForPenSize(FW_CRect& rect, FW_Fixed penSize) const
  647. {
  648.     FW_Fixed half = FW_Half(penSize);
  649.     rect.Inset(-half, -half);
  650. }
  651.  
  652. //----------------------------------------------------------------------------------------
  653. // CBaseShape::ChangeRenderVerb
  654. //----------------------------------------------------------------------------------------
  655.  
  656. void CBaseShape::ChangeRenderVerb(Environment* ev, CDrawPart* part, unsigned short renderVerb)
  657. {
  658.     CheckPromise(ev, part);
  659.     
  660.     ClearCache();
  661.     fRenderVerb = renderVerb;
  662. }
  663.  
  664. //----------------------------------------------------------------------------------------
  665. // CBaseShape::GetObjectClass
  666. //----------------------------------------------------------------------------------------
  667.  
  668. ODDescType CBaseShape::GetObjectClass() const
  669. {
  670.     return kShapeClass;
  671. }
  672.  
  673. //----------------------------------------------------------------------------------------
  674. // CBaseShape::HasProperty
  675. //----------------------------------------------------------------------------------------
  676.  
  677. FW_Boolean CBaseShape::HasProperty(ODDescType whichProperty) const
  678. {
  679.     FW_Boolean hasProperty;
  680.     
  681.     switch (whichProperty)
  682.     {
  683.         case kShapeTypeProperty:
  684.         case pColor:
  685.         case pPosition:
  686.         case pBounds:
  687.         case pIndex:
  688.             hasProperty = TRUE;
  689.             break;
  690.         
  691.         default:
  692.             hasProperty = FW_MScriptable::HasProperty(whichProperty);
  693.             break;
  694.     }
  695.     return hasProperty;
  696. }
  697.  
  698. //----------------------------------------------------------------------------------------
  699. // CBaseShape::GetProperty
  700. //----------------------------------------------------------------------------------------
  701.  
  702. FW_Boolean CBaseShape::GetProperty(Environment* ev,
  703.                                 FW_CPart* part,
  704.                                 FW_CDesc& propertyValue, 
  705.                                 ODDescType whichProperty,
  706.                                 ODDescType desiredType) const
  707. {
  708.     FW_Boolean result = TRUE;
  709.     
  710.     switch (whichProperty)
  711.     {
  712.         case kShapeTypeProperty:
  713.             {
  714.                 ODDescType    shapeType;
  715.                 switch (GetShapeType())
  716.                 {
  717.                     case kLineShape:
  718.                         shapeType = kLineShapeType;
  719.                         break;
  720.                         
  721.                     case kRectShape:
  722.                         shapeType = kRectShapeType;
  723.                         break;
  724.                         
  725.                     case kOvalShape:
  726.                         shapeType = kOvalShapeType;
  727.                         break;
  728.                         
  729.                     case kRRectShape:
  730.                         shapeType = kRRectShapeType;
  731.                         break;
  732.                         
  733.                     case kTextShapeType:
  734.                         shapeType = kTextShapeType;
  735.                         break;
  736.                         
  737.                     default:
  738.                         FW_THROW(FW_XException(errAEEventNotHandled));
  739.                         break;
  740.                 }
  741.                 propertyValue.PutEnumeratedType(shapeType);
  742.             }
  743.             break;
  744.             
  745.         case pColor:
  746.             {
  747.                 FW_CColor color = fFillInk.GetForeColor();
  748.                 propertyValue << color;
  749.             }
  750.             break;
  751.                         
  752.         case pPosition:
  753.             propertyValue << GetRectGeometry().TopLeft().AsPlatformPoint();
  754.             break;
  755.             
  756.         case pBounds:
  757.             // propertyValue << GetRectGeometry();
  758.             break;
  759.             
  760.         default:
  761.             result = FW_MScriptable::GetProperty(ev, part, propertyValue, whichProperty, desiredType);
  762.             break;
  763.     }
  764.     
  765.     return result;
  766. }
  767.  
  768. //----------------------------------------------------------------------------------------
  769. // CBaseShape::SetProperty
  770. //----------------------------------------------------------------------------------------
  771.  
  772. void CBaseShape::SetProperty(Environment* ev,
  773.                             FW_CPart* part,
  774.                             FW_CDesc& propertyValue, 
  775.                             ODDescType whichProperty)
  776. {    
  777.     switch (whichProperty)
  778.     {
  779.         case pColor:
  780.             {
  781.                 CDrawPart* drawPart = FW_DYNAMIC_CAST(CDrawPart, part);
  782.                 if (drawPart && HasFillStyle())
  783.                 {
  784.                     FW_CColor newColor;
  785.                     propertyValue >> newColor;
  786.         
  787.                     FW_CColor oldColor;
  788.                     GetColor(TRUE, oldColor);
  789.                     
  790.                     if (newColor != oldColor)
  791.                     {
  792.                         ChangeFillColor(ev, drawPart, newColor);
  793.                         drawPart->GetDrawContent()->RedrawShape(ev, this);
  794.                     }
  795.                 }
  796.             }
  797.             break;
  798.             
  799.         case pPosition:
  800.             {
  801.                 CDrawPart* drawPart = FW_DYNAMIC_CAST(CDrawPart, part);
  802.                 
  803.                 if (drawPart)
  804.                 {
  805.                     FW_SPlatformPoint     newPlatformPosition;
  806.                     FW_CRect            bounds = GetRectGeometry();
  807.                     
  808.                     propertyValue >> newPlatformPosition;
  809.                 
  810.                     FW_CPoint newPosition(newPlatformPosition);
  811.                     
  812.                     drawPart->GetDrawContent()->RedrawShape(ev, this);    // inval the old location
  813.                     OffsetShape(ev, newPosition.x - bounds.left, newPosition.y - bounds.top);
  814.                     drawPart->GetDrawContent()->RedrawShape(ev, this);  // inval the new location
  815.                 }
  816.             }
  817.             break;
  818.             
  819.         default:
  820.             FW_MScriptable::SetProperty(ev, part, propertyValue, whichProperty);
  821.             break;
  822.     }
  823. }
  824.  
  825. //----------------------------------------------------------------------------------------
  826. // CBaseShape::GetUndoStrings
  827. //----------------------------------------------------------------------------------------
  828.  
  829. void CBaseShape::GetUndoStrings(Environment* ev,
  830.                                 FW_CPart* part,
  831.                                 ODDescType whichProperty,
  832.                                 FW_CString& undoString,
  833.                                 FW_CString& redoString) const
  834. {
  835.     if (whichProperty == pColor)
  836.     {
  837.         FW_CSharedLibraryResourceFile resFile(ev);
  838.         ::FW_LoadStringByID(ev, resFile, kDrawUndoStrings, MULTISTRINGRES, kUndoFillColorMsg, undoString);
  839.         ::FW_LoadStringByID(ev, resFile, kDrawUndoStrings, MULTISTRINGRES, kRedoFillColorMsg, redoString);
  840.     }
  841.     else
  842.         FW_MScriptable::GetUndoStrings(ev, part, whichProperty, undoString, redoString);
  843. }
  844.  
  845. //----------------------------------------------------------------------------------------
  846. // CBaseShape::Read
  847. //----------------------------------------------------------------------------------------
  848.  
  849. void* CBaseShape::Read(FW_CReadableStream& stream, FW_ClassTypeConstant type)
  850. {
  851. FW_UNUSED(stream);
  852. FW_UNUSED(type);
  853.     FW_DEBUG_MESSAGE("CBaseShape::Read should never be called");
  854.     return NULL;
  855. }
  856.  
  857. //----------------------------------------------------------------------------------------
  858. // CBaseShape::Write
  859. //----------------------------------------------------------------------------------------
  860.  
  861. void CBaseShape::Write(FW_CWritableStream& stream, FW_ClassTypeConstant type, const void *object)
  862. {
  863. FW_UNUSED(type);
  864.      ((CBaseShape*)object)->Flatten(stream);
  865. }
  866.  
  867. //----------------------------------------------------------------------------------------
  868. // CBaseShape::GetUpdateBox
  869. //----------------------------------------------------------------------------------------
  870.  
  871. void CBaseShape::GetUpdateBox(Environment* ev, ODShape* updateBox) const
  872. {
  873.     FW_CRect bounds = GetRectGeometry();    
  874.  
  875.     const FW_Fixed fxMargin = FW_IntToFixed(3);
  876.  
  877.     bounds.left        -= fxMargin;
  878.     bounds.top        -= fxMargin;
  879.     bounds.right    += fxMargin;
  880.     bounds.bottom    += fxMargin;
  881.  
  882.     ODRect odBounds = bounds;
  883.     updateBox->SetRectangle(ev, &odBounds);
  884. }
  885.  
  886. //----------------------------------------------------------------------------------------
  887. // CBaseShape::GetUpdateBox
  888. //----------------------------------------------------------------------------------------
  889.  
  890. void CBaseShape::GetUpdateBox(FW_CRect& updateBox) const
  891. {
  892.     updateBox = GetRectGeometry();
  893.  
  894.     const FW_Fixed fxMargin = FW_IntToFixed(3);
  895.  
  896.     updateBox.left        -= fxMargin;
  897.     updateBox.top        -= fxMargin;
  898.     updateBox.right        += fxMargin;
  899.     updateBox.bottom    += fxMargin;
  900. }
  901.  
  902. //----------------------------------------------------------------------------------------
  903. // CBaseShape::GetDragRect
  904. //----------------------------------------------------------------------------------------
  905.  
  906. void CBaseShape::GetDragRect(FW_CRect& dragRect) const
  907. {
  908.     dragRect = GetRectGeometry();
  909.     AdjustRectForPenSize(dragRect, GetPenSize());
  910. }
  911.  
  912. //----------------------------------------------------------------------------------------
  913. // CBaseShape::GetResizeStyle
  914. //----------------------------------------------------------------------------------------
  915.  
  916. FW_CStyle CBaseShape::GetResizeStyle() const
  917. {
  918.     FW_CStyle resizeStyle(GetPenSize(), FW_kGrayPat);
  919.     return resizeStyle;
  920. }
  921.  
  922. //----------------------------------------------------------------------------------------
  923. // CBaseShape::SubtractToWindowClip
  924. //----------------------------------------------------------------------------------------
  925. //    ATTENTION: windowClip is in Window coordinates. tempShape is just a working shape. It is
  926. //    allocated by CDrawFrame::ClipEmbeddedFacets so I don't have to allocate one everytime.
  927.  
  928. void CBaseShape::SubtractToWindowClip(Environment *ev, 
  929.                                         CDrawFacetClipper* facetClipper, 
  930.                                         ODFacet* containingFacet, 
  931.                                         ODShape* windowClip, 
  932.                                         ODShape* tempShape)
  933. {
  934. FW_UNUSED(facetClipper);
  935.  
  936.     GetClipRegion(ev, tempShape);
  937.     FW_CAcquiredODTransform aqWindowContentTransform = containingFacet->AcquireWindowContentTransform(ev, NULL);
  938.     tempShape->Transform(ev, aqWindowContentTransform);        // in window coordinate
  939.     windowClip->Subtract(ev, tempShape);
  940. }
  941.  
  942. //----------------------------------------------------------------------------------------
  943. // CBaseShape::WhichHandle
  944. //----------------------------------------------------------------------------------------
  945.  
  946. short CBaseShape::WhichHandle(FW_CGraphicContext& gc, const FW_CPoint& mouse) const
  947. {
  948.     FW_CPoint penSize = gc.DeviceToLogical(4, 4);
  949.     for (short i=1; i<=fNumberOfHandles; i++)
  950.     {
  951.         CalcHandle(i, CBaseShape::gWorkingHandle, penSize);
  952.         if (CBaseShape::gWorkingHandle->HitTest(gc, mouse, FW_kFixed0))
  953.             return i;
  954.     }
  955.         
  956.     return 0;
  957. }
  958.  
  959. //----------------------------------------------------------------------------------------
  960. // CBaseShape::IsInLinkDestination
  961. //----------------------------------------------------------------------------------------
  962. FW_Boolean CBaseShape::IsInLinkDestination(Environment* ev)
  963. {
  964.     return IsSubscribed();
  965. }
  966.